package com.wpzf.zxhc.controller;


import com.wpzf.common.core.utils.ServletUtils;
import com.wpzf.common.core.web.domain.AjaxResult;
import com.wpzf.common.log.annotation.Log;
import com.wpzf.common.log.enums.BusinessType;
import com.wpzf.common.security.service.TokenService;
import com.wpzf.system.api.model.LoginUser;
import com.wpzf.zxhc.domain.WpCjTbhcjg2023DTO;
import com.wpzf.zxhc.service.StaticService;
import com.wpzf.zxhc.service.WpzfShTbService;
import com.wpzf.zxhc.service.WpzfZgTbTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/shtb")
public class WpzfShTbController {

    @Autowired
    WpzfShTbService wpzfShTbService;

    @Autowired
    TokenService tokenService;

    @Autowired
    WpzfZgTbTaskService wpzfZgTbTaskService;

    @Log(title ="获取审核图斑列表",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/queryShtbTask", method = RequestMethod.POST)
    AjaxResult queryShtbTask(@RequestBody Map<String,Object> parms) {
        try {
            LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
            parms.put("realname",loginUser.getSysUser().getNickName());
            parms.put("username",loginUser.getUsername());
            List<Map<String, Object>> rest = wpzfShTbService.queryShtbTask(parms);
            Integer cnt = wpzfShTbService.queryShtbTaskCount(parms);
            return AjaxResult.success("获取成功", rest,cnt);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title ="获取当前所有审核任务的批次",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/get_sh_pchlist", method = RequestMethod.POST)
    AjaxResult get_sh_pchlist(@RequestBody Map<String,Object> parms)
    {
        try
        {
            List<Map<String, Object>> rest = wpzfShTbService.get_sh_pchlist(parms);
            return AjaxResult.success("获取成功", rest);
        }
        catch (Exception ex)
        {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title ="获取当前所有审核任务的省份",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_sh_Provs", method = RequestMethod.POST)
    AjaxResult query_sh_Provs(@RequestBody Map<String,Object> parms) {
        try {
            LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
            parms.put("realname",loginUser.getSysUser().getNickName());
            parms.put("username",loginUser.getUsername());
            List<Map<String, Object>> rest = wpzfShTbService.query_sh_Provs(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title ="审核任务根据省查所有区县",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_sh_Citys", method = RequestMethod.POST)
    AjaxResult query_sh_Citys(@RequestBody Map<String,Object> parms) {
        try {
            List<Map<String, Object>> rest = wpzfShTbService.query_sh_Citys(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title ="当前图斑进行整改",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/add_zgtb", method = RequestMethod.POST)
    AjaxResult add_zgtb(@RequestBody Map<String,Object> parms)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        try
        {
            String submitdate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime());
            ModelMap map = new ModelMap();
            map.put("tbbh", parms.get("tbbh") + "");
            map.put("xzqdm", parms.get("xzqdm") + "");
            map.put("pdlx", parms.get("pdlx") + "");
            map.put("pch",parms.get("pch") + "");
            map.put("sh_realname",loginUser.getSysUser().getNickName());
            map.put("sh_username",loginUser.getUsername());
            map.put("zgyy",parms.get("zgyy") + "");
            map.put("ywhj",parms.get("ywhj") + "");
            map.put("submitdate",submitdate);
            map.put("sfzg","否");
            map.put("state","0");

            Map<String, Object> model = wpzfZgTbTaskService.query_unit_zgtbbyid(parms);
            if(model!=null)
            {
                parms.put("state","1");
                wpzfZgTbTaskService.update_unit_zgtb_state(parms);
            }

            int rest=wpzfZgTbTaskService.zgSubmit(map);
            return AjaxResult.success("获取成功", rest);
        }
        catch (Exception ex)
        {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title ="获取审核图斑左侧列表",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/getShtbLeftlist", method = RequestMethod.POST)
    AjaxResult getShtbLeftlist(@RequestBody Map<String,Object> parms) {
        try {
            LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
            parms.put("realname",loginUser.getSysUser().getNickName());
            parms.put("username",loginUser.getUsername());
            List<Map<String, Object>> rest = wpzfShTbService.getShtbLeftlist(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title ="获取审核图斑 最终结果",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/getShtbZzjg", method = RequestMethod.POST)
    AjaxResult getShtbZzjg(@RequestBody Map<String,Object> parms) {
        try {
            WpCjTbhcjg2023DTO rest = wpzfShTbService.getShtbZzjg(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }

    @Log(title ="查询核查结果说明",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/getHcjgsmList", method = RequestMethod.POST)
    AjaxResult getHcjgsmList(@RequestBody Map<String,Object> parms) {
        try {
            List<Map<String,Object>> rest = wpzfShTbService.getHcjgsmList(parms);
            return AjaxResult.success("获取成功", rest);
        } catch (Exception ex) {
            return AjaxResult.error("获取失败", ex.toString());
        }
    }


}
